package com.wolf.cx330.main.act

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.Layout
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import com.blankj.utilcode.util.ToastUtils
import com.wolf.cx330.R
import com.wolf.cx330.base.BaseActivity
import com.wolf.cx330.camera.CameraAct
import com.wolf.cx330.camera.CameraXAct
import com.wolf.cx330.config.Constants
import com.wolf.cx330.data_binding.DataBindingAct
import com.wolf.cx330.download.DownloadAct
import com.wolf.cx330.main.adapter.MainAdapter
import com.wolf.cx330.room.RoomAct
import com.wolf.cx330.utils.act.CompressAct
import com.wolf.cx330.utils.act.ImgSelectAct
import com.wolf.cx330.view.act.*
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*


class MainAct : BaseActivity() {
    private val count = 4
    val random = Random()

    companion object {
        fun actionStart(context: Context) =
            context.startActivity(Intent(context, MainAct::class.java))
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        init()
        //  AES 加密测试
//        val key = "7emsp8OvYGxEteaiElrgpQ=="
//        val enVal = AESUtils.encrypt(key,"1232131231312231")
//        println("【IM】MainAct  onCreate:String(enVal) ${enVal}")
//        val ss = AESUtils.decrypt(key,enVal)
//        println("【IM】MainAct  onCreate:String(ss) $ss")
        // val deVal = EncryptUtils.decryptAES(enVal,key.toByteArray(),"","".toByteArray())
        //  println("【IM】MainAct  onCreate:String(deVal) ${String(deVal)}")


    }

    /**
     * 获取TextView 所有字高度
     */
    private fun getTextViewHeight(tv: TextView): Int {
        val layout: Layout = tv.layout
        val desired: Int = layout.getLineTop(tv.lineCount)
        val padding = tv.compoundPaddingTop + tv.compoundPaddingBottom
        return desired + padding
    }

    private fun init() {
        menuRecyclerView.layoutManager =
            GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false)
        menuRecyclerView.adapter = MainAdapter(this) { _, m ->
            when (m) {
                Constants.MENU_AVD_ANIM -> {
                    AvdAnimAct.actionStart(this)
                }
                Constants.MENU_VALUE_PROPERTY_ANIM -> {
                    ValuePropertyAnimAct.actionStart(this)
                }
                Constants.MENU_AUTO_SCROLL -> {
                    AutoScrollTextAct.actionStart(this)
                }
                Constants.MENU_SPORT_TEXT -> {
                    SportTextAct.actionStart(this)
                }
                Constants.MENU_CAMERA_VIEW -> {
                    CameraViewAct.actionStart(this)
                }
                Constants.MENU_MATERIAL_EDIT_TEXT -> {
                    MetAct.actionStart(this)
                }
                Constants.MENU_IMAGE_COMPRESS -> {
                    CompressAct.actionStart(this)
                }
                Constants.MENU_TAG_LAYOUT -> {
                    TagAct.actionStart(this)
                }
                Constants.MENU_CAMERA2 -> {
                    CameraAct.actionStart(this)
                }
                Constants.MENU_ECG_VIEW -> {
                    EcgAct.actionStart(this)
                }
                Constants.MENU_IMG_SELECT -> {
                    ImgSelectAct.actionStart(this)
                }
                Constants.MENU_ROOM -> {
                    RoomAct.actionStart(this)
                }
                Constants.MENU_CAMERA_X -> {
                    CameraXAct.actionStart(this)
                }
                Constants.MENU_DOWNLOAD -> {
                    DownloadAct.actionStart(this)
                }
                Constants.MENU_DATA_BINDING_ -> {
                    DataBindingAct.actionStart(this)
                }
                else -> {
                    ToastUtils.showShort("暂无")
                }
            }
        }
    }

}